package com.bdqn.zhang.interceptor;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

import java.util.Map;

/**
 * 通过拦截器实现权限控制，不登录的用户无法直接跳转到主页
 * @param null
 * @return 
 * @author zhangtao
 * @creed: Talk is cheap,show me the code
 * @date 2019/4/1 14:30
 */
public class LoginInterceptor extends AbstractInterceptor {

    @Override
    public String intercept(ActionInvocation actionInvocation) throws Exception {

        String method = actionInvocation.getProxy().getMethod();  //  如果method = login  actionInvocation

        if ("login".equals(method)){
            return actionInvocation.invoke();
        } else {
            Map session = actionInvocation.getInvocationContext().getSession();
            if(session.get("user") != null){
                return actionInvocation.invoke();
            }
            return "login";
        }
    }
}
